/**
 * class name: mask,
 * copyright: maximus zhang,
 * License: MIT-LICENSE,
 * contact: maximus.zhang@gmail.com,
 * required-js: http://hcjs.googlecode.com/svn/trunk/hc.js,
 * update: http://hcjs.googlecode.com/svn/trunk/mask.js
 *
 */
function mask(){
    var A = arguments,
        _ = this;
    _ = ext( _, ext( {elem:'', id:'z-masker', opacity:50, color:'#fff', z : now().getFullYear()-1}, A[0] ) );

    _.uitype = 'mask';

    _.css = 'position:fixed;top:0;left:0;width:100%;height:100%;border:0;'
        + ($$.msie  ? 'filter:alpha(opacity='+ _.opacity +');'
                    : 'opacity:'+ _.opacity/100 +';')
        +'z-index:'+ _.z +';background-color:'+ _.color +';display:none;';
}

mask.prototype = {
    init : function(){
        this.$ = $(this.id) || elm('div').before(me.body.childNodes[0]);
        this.$.style.cssText = this.css;
        this.$.id = this.id;

        this.$.ondblclick = function(){
            window.getSelection && window.getSelection().removeAllRanges();
            return false;
        };

        if ( $$.msie && $$.version<7.0 ) {//todo:for ie6
            this.$.style.position = 'absolute';
            this.$.innerHTML = '<iframe scrolling="no" frameborder="0" style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);z-index:-1;"></iframe>';

            this._ = elm('div').appendTo(this.$);
            this._.style.cssText = this.css;
        }
    return this;
    },

    maskit : function(obj){
        this.elem = $(obj) || $(this.elem);
        if ( this.elem.nodeType ) {
            var pz = pos(this.elem);
            this.$.style.cssText = 'position:absolute;top:'+
                pz.top +'px;left:'+ pz.left +'px;width:'+ pz.width +
                'px;height:'+ pz.height +'px;';
        }
    return this;
    },

    setColor : function(c){
        this.color = c || this.color;
        this.$.style.backgroundColor = this.color;
    return this;
    },

    setOpacity : function(x){
        this.opacity = x || this.opacity;
        if ( $$.msie ) {
            this.$.style.filter = 'alpha(opacity='+ this.opacity +')';
        } else {
            this.$.style.opacity = this.opacity/100;
        }
    return this;
    },

    show : function(){
        this.$.style.display = '';
    return this;
    },

    hide : function(){
        this.$.style.display = 'none';
    return this;
    }

};
